import axios from "axios"
// import Vue from "vue"
import store from '../../store'
import router from "../../router"
let http = axios.create()

//请求拦截

http.interceptors.request.use(req=>{
    //配置请求头
    if(store.state.userInfo){

        req.headers.authorization= store.state.userInfo.token     
    }
    
   
    
    return req
})

//响应拦截
http.interceptors.response.use(res=>{

    if(res.data.msg=="登录已过期或访问权限受限"){
        alert(res.data.msg);
        this.$router.push("/login")
        // window.location.href("http://localhost:8080/login");
    }

    return res.data
})

export default http